from rest_framework import serializers
from goods.models import GoodsChannel,GoodsCategory,GoodsChannelGroup



# 1.频道分级展示
class ChannelViewSerializer(serializers.ModelSerializer):

    # 1.重写group,category
    category = serializers.StringRelatedField(read_only=True)
    category_id = serializers.IntegerField()

    group = serializers.StringRelatedField(read_only=True)
    group_id = serializers.IntegerField()

    class Meta:
        model = GoodsChannel
        fields = "__all__"

# 2.频道分级组的
class ChannelTypeViewSerializer(serializers.ModelSerializer):
    class Meta:
        model = GoodsChannelGroup
        fields = "__all__"

# 3.展示频道一级分类
class ChannelCategoriesViewSerializer(serializers.ModelSerializer):
    parent = serializers.StringRelatedField(read_only=True)
    parent_id = serializers.IntegerField()

    class Meta:
        model = GoodsCategory
        fields = "__all__"